:root {
  --bg: #faf6f0;
  --bg-decoration: #f3ebe0;
  --text: #1f1a2e;
  --text-soft: #4a4458;
  --muted: #8b8499;
  --card-bg: #ffffff;
  --card-border: #ece5d8;
  --shadow-sm: 0 2px 6px rgba(60, 30, 80, 0.05);
  --shadow: 0 10px 30px -8px rgba(60, 30, 80, 0.18);
  --shadow-hover: 0 20px 40px -10px rgba(60, 30, 80, 0.28);
  --radius: 20px;
  --radius-sm: 10px;
  --accent: #c2410c;
  --accent-deep: #7c2d12;
  --magic: #6b21a8;
  --gold: #d4a017;

  --MudWing: #8B4513;
  --SandWing: #B8851E;
  --SkyWing: #C8102E;
  --SeaWing: #1E3A8A;
  --IceWing: #2F7AA8;
  --RainWing: #2E8B57;
  --NightWing: #2D1B4E;
  --SilkWing: #6B3FB0;
  --HiveWing: #C26200;
  --LeafWing: #228B22;
  --Hybrid: #8B5CB8;
  --WildWing: #7D5A3E;
  --Scavenger: #8B6F47;
  --BeetleWing: #2E7D6B;

  --serif: "Georgia", "Iowan Old Style", "Palatino", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(196, 87, 12, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 10%, rgba(107, 33, 168, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 100%, rgba(30, 58, 138, 0.04) 0%, transparent 60%);
}

/* ===== Header ===== */

header {
  position: relative;
  text-align: center;
  padding: 3.5rem 1.5rem 2rem;
  overflow: hidden;
}

header::before, header::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 80px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--accent), transparent);
  opacity: 0.5;
}

header::before { left: max(2rem, calc(50% - 280px)); }
header::after { right: max(2rem, calc(50% - 280px)); }

.title-name {
  margin: 0 0 0.3rem;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 4.4vw, 2.7rem);
  font-style: italic;
  font-weight: 700;
  letter-spacing: 0.005em;
  background: linear-gradient(135deg, #be185d 0%, #d4a017 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent-deep) 0%, var(--accent) 50%, var(--magic) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.subtitle {
  margin: 0.6rem 0 0;
  color: var(--text-soft);
  font-size: 1.1rem;
  font-style: italic;
  font-family: var(--serif);
}

.crown {
  display: inline-block;
  margin: 0 0.4rem;
  font-size: 0.9em;
  color: var(--gold);
}

/* ===== Controls ===== */

.controls {
  max-width: 1200px;
  margin: 0 auto 2rem;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  align-items: center;
}

.search-wrap {
  position: relative;
  width: 100%;
  max-width: 460px;
}

.search-wrap::before {
  content: "🔍";
  position: absolute;
  left: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  opacity: 0.5;
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 0.95rem 1.2rem 0.95rem 2.8rem;
  font-size: 1.05rem;
  font-family: var(--sans);
  border: 1.5px solid var(--card-border);
  border-radius: 999px;
  background: white;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(194, 65, 12, 0.12);
}

.tribe-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  max-width: 800px;
}

.tribe-chip {
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--card-border);
  border-radius: 999px;
  background: white;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.18s;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  box-shadow: var(--shadow-sm);
}

.tribe-chip::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--chip-color, #999);
  box-shadow: 0 0 0 2px white, 0 0 0 3px var(--chip-color, #999);
}

.tribe-chip:hover {
  border-color: var(--chip-color, #999);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.tribe-chip.active {
  background: var(--chip-color, #999);
  color: white;
  border-color: var(--chip-color, #999);
}

.tribe-chip.active::before {
  background: white;
  box-shadow: 0 0 0 2px var(--chip-color, #999), 0 0 0 3px white;
}

.result-count {
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* ===== Cards Grid ===== */

.cards {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.5rem;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s;
  display: flex;
  flex-direction: column;
  position: relative;
}

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

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

.card-banner {
  position: relative;
  height: 14px;
  background: linear-gradient(90deg, var(--main-color) 0%, var(--secondary-color) 100%);
}

.card-image-wrap {
  position: relative;
  height: 200px;
  overflow: hidden;
  /* Very subtle tribe-color tint so all cards read as the same neutral
     canvas — keeps grid cohesive across different artists' canon art. */
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--main-color) 12%, #fafaf6) 0%,
    color-mix(in srgb, var(--secondary-color) 10%, #fafaf6) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Cards that fall back to the SVG placeholder keep the bolder gradient
   so the cute character SVG sits on a rich tribe-colored background. */
.card-image-wrap:has(.placeholder-content),
.modal-image-wrap:has(.placeholder-content) {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--main-color) 32%, white) 0%,
    color-mix(in srgb, var(--secondary-color) 26%, white) 100%);
}

.card-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  padding: 0.7rem;
  cursor: zoom-in;
  filter: saturate(0.97) contrast(1.01);
}

.modal-image-wrap img {
  cursor: zoom-in;
  filter: saturate(0.97) contrast(1.01);
}

.placeholder-content {
  text-align: center;
  padding: 1rem;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.dragon-svg-wrap {
  width: 75%;
  max-width: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dragon-svg {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.18));
  animation: dragon-breathe 3.2s ease-in-out infinite;
}

@keyframes dragon-breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.03) translateY(-3px); }
}

.placeholder-content .placeholder-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7);
  letter-spacing: 0.01em;
}

.modal-image-wrap .dragon-svg-wrap {
  max-width: 280px;
}

.modal-image-wrap .placeholder-label {
  font-size: 1.3rem;
}

.card-body {
  padding: 1.1rem 1.3rem 1.3rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-name {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.card-tribe-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.3rem 0 1rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tribe-color);
  align-self: flex-start;
}

.card-tribe-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tribe-color);
}

.color-row {
  display: flex;
  gap: 0.45rem;
  margin: auto 0 0;
  padding-top: 0.5rem;
}

.color-swatch {
  flex: 1;
  height: 38px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  position: relative;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.08);
  cursor: help;
}

.color-swatch[data-label]::after {
  content: attr(data-label);
  position: absolute;
  bottom: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  white-space: nowrap;
}

.color-row { margin-bottom: 1.5rem; }

/* ===== Empty state ===== */

.empty {
  text-align: center;
  color: var(--muted);
  padding: 4rem 1rem;
  font-size: 1.15rem;
  font-style: italic;
  font-family: var(--serif);
  grid-column: 1 / -1;
}

.empty .empty-glyph {
  font-size: 3rem;
  display: block;
  margin-bottom: 0.8rem;
  opacity: 0.5;
}

/* ===== Footer ===== */

footer {
  text-align: center;
  padding: 2.5rem 1.5rem 3rem;
  color: var(--muted);
  font-size: 0.88rem;
  max-width: 700px;
  margin: 0 auto;
}

footer p {
  margin: 0 0 0.9rem;
  font-style: italic;
}

footer .dedication {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-style: italic;
  color: var(--accent-deep);
  margin-bottom: 1.2rem;
  letter-spacing: 0.01em;
}

footer .dedication span {
  background: linear-gradient(135deg, var(--accent) 0%, var(--magic) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 700;
  letter-spacing: 0.02em;
}

footer .disclaimer {
  font-size: 0.75rem;
  font-style: normal;
  color: var(--muted);
  opacity: 0.7;
  line-height: 1.5;
  border-top: 1px solid var(--card-border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

/* ===== Modal ===== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 26, 46, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fadeIn 0.2s ease-out;
}

.modal-backdrop.open { display: flex; }

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

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal {
  background: white;
  border-radius: 24px;
  max-width: 560px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-banner {
  height: 18px;
  background: linear-gradient(90deg, var(--main-color) 0%, var(--secondary-color) 50%, var(--accent-color) 100%);
}

.modal-close {
  position: absolute;
  top: 4.25rem;
  right: 1rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.97);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text);
  z-index: 2;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}

.modal-close:hover { transform: scale(1.1); }

.modal-image-wrap {
  position: relative;
  height: 320px;
  overflow: hidden;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--main-color) 12%, #fafaf6) 0%,
    color-mix(in srgb, var(--secondary-color) 10%, #fafaf6) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  padding: 1rem;
}

.modal-image-wrap .placeholder-content .dragon-glyph {
  font-size: 5rem;
}

.modal-body {
  padding: 1.8rem 2rem 2.2rem;
}

.modal-name {
  margin: 0 0 0.3rem;
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-tribe-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tribe-color);
}

.modal-tribe-badge::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tribe-color);
}

.color-section {
  margin: 0 0 1.5rem;
  padding: 1rem 1.1rem 1.6rem;
  background: var(--bg);
  border-radius: 14px;
}

.color-section-title {
  margin: 0 0 0.8rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.modal-body .color-row {
  margin-bottom: 1.5rem;
}

.modal-body .color-swatch {
  height: 50px;
}

.description {
  font-size: 1.05rem;
  color: var(--text);
  margin: 0 0 1rem;
  line-height: 1.6;
}

.main-detail {
  font-size: 1.05rem;
  color: var(--text);
  margin: 0 0 1.4rem;
  line-height: 1.65;
}

.info-section {
  margin: 0 0 1.5rem;
}

.info-section-title {
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.fun-facts {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.fun-facts li {
  position: relative;
  padding: 0.6rem 0.9rem 0.6rem 2.1rem;
  background: var(--bg);
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
}

.fun-facts li::before {
  content: "✨";
  position: absolute;
  left: 0.7rem;
  top: 0.55rem;
  font-size: 0.9rem;
}

.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.book-tag {
  display: inline-block;
  padding: 0.32rem 0.75rem;
  background: white;
  color: var(--tribe-color, var(--text-soft));
  border: 1.5px solid var(--tribe-color, var(--card-border));
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.special {
  font-size: 0.92rem;
  color: var(--text-soft);
  margin: 0 0 1.3rem;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border-left: 3px solid var(--tribe-color);
  border-radius: 0 8px 8px 0;
}

.special::before {
  content: "✨ ";
  margin-right: 0.2rem;
}

.wiki-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.6rem 1rem;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  transition: all 0.15s;
}

.wiki-link:hover {
  background: var(--accent);
  color: white;
}

@media (max-width: 480px) {
  header { padding: 2.5rem 1rem 1.5rem; }
  .cards { grid-template-columns: 1fr; padding: 0 1rem 2rem; }
  .modal-image-wrap { height: 240px; }
  .modal-body { padding: 1.4rem 1.4rem 1.8rem; }
  .modal-name { font-size: 1.8rem; }
}

/* ===== Life stages (egg / dragonet / adult — Iris's original dragons) ===== */

.life-stages-row {
  display: flex;
  gap: 0.75rem;
}

.life-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.life-stage-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  background: #faf6f0;
  border: 2px solid var(--card-border);
  cursor: zoom-in;
  transition: transform 0.15s, box-shadow 0.15s;
}

.life-stage-img:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(60, 30, 80, 0.18);
}

.life-stage-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

/* ===== Creator badge (for original dragons drawn by a real person) ===== */

.creator-badge {
  display: block;
  width: fit-content;
  clear: both;
  margin: 0.6rem 0 0.9rem;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: white;
  background: linear-gradient(90deg, #e63946, #f4a300, #2a9d3f, #1982c4, #6a4c93);
  background-size: 200% 100%;
  animation: rainbow-shift 6s linear infinite;
  box-shadow: 0 2px 8px rgba(106, 76, 147, 0.3);
}

@keyframes rainbow-shift {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.modal-body .creator-badge {
  font-size: 0.9rem;
  margin: 0.8rem 0 1.3rem;
}

/* ===== Image lightbox (click to enlarge for drawing) ===== */

.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 25, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1.5rem;
  animation: fadeIn 0.2s ease-out;
  cursor: zoom-out;
}

.lightbox-container {
  position: relative;
  max-width: min(96vw, 1200px);
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: default;
}

.lightbox-image {
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  background: white;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.lightbox-caption {
  margin-top: 1.1rem;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.01em;
}

.lightbox-close {
  position: absolute;
  top: -52px;
  right: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.96);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s;
}

.lightbox-close:hover { transform: scale(1.08); }

@media (max-width: 480px) {
  .lightbox-close { top: -48px; width: 40px; height: 40px; }
  .lightbox-caption { font-size: 1.3rem; }
}

/* Fallback for browsers without color-mix (older Safari etc.) */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .card-image-wrap,
  .modal-image-wrap {
    background: linear-gradient(135deg, var(--main-color) 0%, var(--secondary-color) 100%);
    opacity: 0.95;
  }
}
