/* =========================================================
   RESET
========================================================= */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #f5f6f8;
  color: #202124;
}

/* =========================================================
   TOP BAR
========================================================= */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;

  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;

  min-height: 64px;
  padding: 10px 18px;

  border-bottom: 1px solid #dfe1e5;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  text-align: center;
}

.back-button,
.recs-link {
  color: #1a73e8;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.recs-link {
  justify-self: end;
}

/* =========================================================
   PAGE
========================================================= */

.page-container {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 50px;
}

/* =========================================================
   SEARCH
========================================================= */

.search-section {
  position: sticky;
  top: 64px;
  z-index: 40;

  padding: 14px 0;
  background: #f5f6f8;
}

.civ-search {
  width: 100%;
  padding: 15px 18px;

  border: 1px solid #dfe1e5;
  border-radius: 999px;

  background: white;
  font-size: 17px;
  outline: none;

  box-shadow: 0 2px 8px rgba(60, 64, 67, .1);
}

.civ-search:focus {
  border-color: #1a73e8;
  box-shadow:
    0 0 0 3px rgba(26,115,232,.12),
    0 3px 10px rgba(60,64,67,.12);
}

.search-hint {
  margin-top: 8px;
  text-align: center;
  color: #666;
  font-size: 13px;
}

/* =========================================================
   SELECTED CIV
========================================================= */

.selected-civ {
  margin: 18px 0 30px;
  padding: 20px;

  border-radius: 16px;
  background: white;

  box-shadow: 0 4px 18px rgba(0,0,0,.12);
}

.selected-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.selected-label {
  font-size: 12px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.selected-header h2 {
  margin: 6px 0 0;
  font-size: 30px;
}

.close-button {
  width: 42px;
  height: 42px;

  border: 0;
  border-radius: 50%;

  background: #eceff1;

  font-size: 26px;
  cursor: pointer;
}

.close-button:hover {
  background: #dfe3e6;
}

.selected-image-wrapper {
  margin-top: 20px;
}

.selected-civ-image {
  display: block;
  width: 100%;
  height: auto;

  border-radius: 12px;
}

.image-loading {
  padding: 60px;
  text-align: center;
  color: #666;
}

/* =========================================================
   CIV GRID
========================================================= */

.civ-count {
  margin-bottom: 14px;
  color: #666;
  font-size: 14px;
}

.civ-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 14px;
}

.civ-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  gap: 10px;

  min-height: 150px;

  padding: 16px;

  border: 2px solid transparent;
  border-radius: 16px;

  background: white;

  cursor: pointer;

  transition:
    transform .15s,
    box-shadow .15s,
    border-color .15s;
}

.civ-card:hover {
  transform: translateY(-3px);

  border-color: #1a73e8;

  box-shadow: 0 8px 18px rgba(0,0,0,.12);
}

.civ-card.active {
  border-color: #1a73e8;
  background: #e8f0fe;
}

.civ-card-emblem {
  width: 82px;
  height: 82px;

  object-fit: contain;

  transition: transform .15s;
}

.civ-card:hover .civ-card-emblem {
  transform: scale(1.08);
}

.civ-card-name {
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  line-height: 1.25;
}

.no-results {
  padding: 50px;
  text-align: center;
  color: #666;
}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 900px) {

  .civ-grid {
    grid-template-columns: repeat(4, 1fr);
  }

}

@media (max-width: 650px) {

  .topbar {
    min-height: 58px;
    padding: 8px 12px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .page-container {
    width: calc(100% - 18px);
    padding-top: 12px;
  }

  .search-section {
    top: 58px;
  }

  .search-hint {
    display: none;
  }

  .selected-civ {
    padding: 12px;
  }

  .selected-header h2 {
    font-size: 22px;
  }

  .civ-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .civ-card {
    min-height: 115px;
    padding: 10px;
    gap: 6px;
  }

  .civ-card-emblem {
    width: 58px;
    height: 58px;
  }

  .civ-card-name {
    font-size: 12px;
  }

}

@media (max-width: 420px) {

  .civ-grid {
    grid-template-columns: repeat(2, 1fr);
  }

}
