*,
*::before,
*::after {
  font-family: var(--site-font) !important;
}

.hidden {
  display: none !important;
}

.version-select option {
  padding: 4px;
}

.games-title {
  color: var(--primary-dark);
  text-align: center;

  margin-top: 0;
  margin-bottom: 2px;
}

.games-filter-toggle {
  display: none;
}

/* SECTION HEADERS */
.series-title {
  margin-top: 12px;   /* was 18px */
  margin-bottom: 6px; /* was 10px */

  color: var(--primary-dark);
  font-size: 22px;
  text-align: center;
  font-weight: bold;
  letter-spacing: 0.3px;
}

.games-result-summary {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.games-result-summary strong {
  color: var(--primary-dark);
  font-size: 20px;
  line-height: 1.2;
}

.games-result-summary span {
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.2;
}

/* GRID */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 260px);
  justify-content: center;

  gap: 14px;

  max-width: 1082px; /* 🔥 perfect 4-fit */
  margin: 0 auto 10px auto;
}

.game-card {
  margin: 0; /* 🔥 cleaner alignment */
}

/* CARD */
.game-card {
  width: 100%;          /* 🔥 IMPORTANT */
  max-width: 260px;     /* slightly bigger than before */

  margin: 0;       /* center inside grid cell */

  display: flex;
  flex-direction: column;
  position: relative;

  background: linear-gradient(#ffffff, #eef3f8);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;        /* slightly more breathing room */

  text-align: center;

  box-shadow:
    inset 0 1px 0 #ffffff,
    0 3px 8px rgba(0,0,0,0.08);
}

.game-card h3 {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;

  margin: 2px 0 1px 0;
}

.game-author {
  font-size: 14px;
  color: #2f3e4e;

  margin: 2px 0 4px 0;

  display: block;
}

.game-author:hover {
  text-decoration: none;
  color: #000;
  cursor: default;
}

.game-card:hover {
  box-shadow:
    inset 0 1px 0 #ffffff,
    0 6px 12px rgba(0,0,0,0.12);
}

.game-card img {
  width: 100%;
  height: 140px;
  border-radius: 6px;
  margin-bottom: 2px;
}

.game-card h3 {
  margin-top: 2px;
  margin: 4px 0 2px 0;
  color: var(--primary-dark);
  font-weight: bold;
}

/* PLAY BUTTON (UPDATED 🔥) */
.game-card .play-btn {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 14px;
}

.game-card .game-author a.game-author-link {
  display: inline;
  margin: 0;
  padding: 0;
  color: #2f5d84;
  text-decoration: none;
  cursor: pointer;
}

.game-card .game-author a.game-author-link:hover,
.game-card .game-author a.game-author-link:focus,
.game-card .game-author a.game-author-link:focus-visible {
  color: #b00000 !important;
  text-decoration: underline !important;
}

.game-card .game-author-link b {
  color: inherit;
}

.text.center-text {
  padding-top: 0;
}

.box-inner.single-column {
  padding-top: 10px;
}

.image-wrapper {
  width: 100%;
  position: relative;
  aspect-ratio: 4 / 3;   /* 🔥 consistent box shape */
  overflow: hidden;
  border-radius: 6px;
}

.image-wrapper img {
  width: 100%;
  height: 100%;

  object-fit: cover;     /* 🔥 fills box cleanly */
  object-position: center;

  display: block;
  cursor: zoom-in;
}

/* POPUP */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.image-modal img {
  max-width: 90%;
  max-height: 90%;
  border-radius: 0;
}

.versions-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 6px;
  margin-bottom: 6px;
  text-align: center;
}

.version-line {
  display: block;
  color: #222;
  text-decoration: none;
  line-height: 1.5;
  font-size: 13px;
}

.version-line:hover {
  color: #2f5d84;
  text-decoration: underline;
}

.versions-header {
  font-weight: bold;
  margin-bottom: 2px;
  font-size: 14px;
  color: #2f5d84;
  text-align: center;
}

.versions-block a {
  display: block;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 2px 0;

  color: #222;
  font-weight: normal;
  font-size: 13px;
  text-decoration: none;
}

.versions-block a:hover,
.versions-block a:focus-visible {
  color: #b00000;
  text-decoration: underline;
}

.version-select {
  font-family: var(--site-font) !important;
  width: 100%;
  max-width: 160px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  margin-top: 4px;

  display: block;
  margin-left: auto;
  margin-right: auto;      /* 🔥 centers the box itself */

  text-align: left;        /* 🔥 LEFT aligned text */
  text-align-last: left;

  appearance: auto;
  -webkit-appearance: menulist;
  -moz-appearance: menulist;

  cursor: pointer;
}

.version-select:hover {
  border-color: #5f86a3;
}

.version-select:focus {
  outline: none;
  border-color: #5f86a3;
}

.play-btn {
  display: inline-block;
  margin-top: 4px;
}

.bottom-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;

  margin-top: auto;
}

.favorite-action {
  position: absolute;
  top: -10px;
  right: -10px;
  z-index: 1;
}

.favorite-action .tooltip {
  bottom: 125%;
  font-size: 12px;
  padding: 5px 10px;
}

.favorite-action:hover .tooltip {
  opacity: 1;
}

.favorite-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 7px;
  border-radius: 50%;
}

.favorite-btn img {
  display: block;
  width: 16px;
  height: 16px;
  margin: 0;
  opacity: 0.72;
}

.favorite-btn.active {
  background: linear-gradient(#b9d0e1, #98b8d0);
  border-color: #467394;
}

.favorite-btn:hover img,
.favorite-btn.active img {
  opacity: 1;
}

.favorite-btn.active img {
  filter: brightness(0) saturate(100%) invert(62%) sepia(89%) saturate(1786%) hue-rotate(360deg) brightness(102%) contrast(105%);
}

/* TABS CONTAINER */
.tabs {
  display: flex;
  justify-content: center;
  gap: 24px;

  margin: 10px 0 4px 0;
  flex-wrap: wrap;

  border-bottom: 2px solid #cfdbe6;
}

/* TAB BUTTON RESET */
.tab-btn {
  background: none;
  border: none;
  padding: 7px 4px;

  font-weight: bold;
  font-size: 17px;
  color: #5a6b78;

  cursor: pointer;
  position: relative;

  transition: color 0.2s ease;
}

/* HOVER */
.tab-btn:hover {
  color: var(--primary-dark);
}

/* ACTIVE TAB */
.tab-btn.active {
  color: var(--primary-dark);
}

/* UNDERLINE INDICATOR */
.tab-btn::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px; /* aligns with border */

  width: 100%;
  height: 2px; /* match border thickness */

  background: transparent;
  transition: background 0.2s ease;
}

.tabs {
  border-bottom: 2px solid #cfdbe6;
}

.text.center-text > .tabs {
  margin-bottom: 6px;
}

.tab-btn.active::after {
  background: var(--primary);
  height: 3px; /* slightly thicker than border */
  bottom: -2px;
}

#tab-content {
  margin-top: 0;
}

.box-inner.single-column:has(#tab-content .games-empty-message) {
  padding-bottom: 14px;
}

#tab-content:has(.games-empty-message) {
  margin-bottom: 0;
}

#tab-content .games-empty-message {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  margin: 8px 0 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(#f9fcff, #edf3f8);
  color: #55748b;
  text-align: center;
  font-style: italic;
  animation: none;
}

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

.control-btn {
  padding: 6px 16px;
}

.search-input {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  display: block;
}

.help-modal {
  position: fixed;
  inset: 0;

  background: rgba(20, 40, 60, 0.65);

  display: flex;
  align-items: center;
  justify-content: center;

  z-index: 9999;

  /* 🔥 THIS FIXES YOUR ISSUE */
  pointer-events: auto;
}

/* compact rows */
.help-body select,
.help-body input {
  width: 100%;
  min-height: 42px;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: linear-gradient(#ffffff, #f5f9fd);
  color: var(--primary-dark);
  font: inherit;
  font-weight: 400;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.06);
}

.help-body select:focus,
.help-body input:focus {
  outline: none;
  border-color: #5f86a3;
  box-shadow: 0 0 0 2px rgba(95,134,163,0.14);
}

/* title input full width */
#search-title {
  grid-column: span 2;
  width: 100%;
  max-width: none;
}

#search-count {
  grid-column: 1 / -1;
  color: #5d7080;
  font-size: 14px;
  min-height: 0;
  text-align: center;
}

#search-count:empty {
  display: none;
}

.help-modal-content {
  width: 640px;
  max-width: 92%;

  background: linear-gradient(#f4f8fc, #e3edf6);
  border: 1px solid var(--border);
  border-radius: 12px;

  box-shadow:
    inset 0 1px 0 #ffffff,
    0 10px 30px rgba(0,0,0,0.3);

  animation: popIn 0.18s ease;
  overflow: hidden;
}

/* HEADER */
.help-header {
  background: linear-gradient(#5f86a3, #4a6f8a);
  color: white;

  font-weight: bold;
  text-align: center;

  padding: 12px;
  font-size: 18px;

  border-bottom: 1px solid #3e5f78;
}

#search-modal .help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  font-size: 22px;
}

#search-modal .help-header button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 8px;
  background: rgba(255,255,255,0.16);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  overflow: hidden;
  text-indent: -999px;
}

#search-modal .help-header button::before,
#search-modal .help-header button::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
  transform-origin: center;
}

#search-modal .help-header button::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

#search-modal .help-header button::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* FOOTER */
.help-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 8px 28px 16px;
  border-top: 0;
}

/* BUTTONS */
.help-footer button {
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 15px;
}

#search-modal .help-footer button {
  box-sizing: border-box;
  flex: 0 0 auto;
  height: 35px;
  min-height: 35px;
  min-width: 0;
  padding: 7px 16px;
  font-size: 14px;
}

#search-modal .help-footer #apply-search {
  width: 79px;
}

#search-modal .help-footer #reset-search {
  width: 67px;
}

.search-results-reset-btn {
  min-height: 40px;
  padding: 8px 18px;
  border-radius: 8px;
}

/* make dropdowns inline grid */
.help-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 20px;
  padding: 20px 28px 6px;
  justify-items: center;
  text-align: left;
}

#sort-modal .help-body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#sort-modal select {
  margin: 0 auto;
  display: block;
  max-width: 280px;
}

@media (max-width: 640px) {
  .help-modal-content {
    width: min(92%, 420px);
  }

  #search-modal .help-header {
    font-size: 21px;
    padding: 12px 14px;
  }

  .help-body {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 18px 18px 8px;
  }

  #search-title,
  #search-count {
    grid-column: 1;
  }

  .help-footer {
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 6px 18px 18px;
  }

  .help-footer button {
    flex: 0 0 auto;
    min-width: 86px;
    width: auto;
    padding: 8px 16px;
  }
}

.games-controls {
  display: grid;
  grid-template-columns: minmax(220px, 275px) minmax(112px, 112px) 44px 44px;
  align-items: center;
  justify-content: center;
  gap: 10px 12px;
  width: min(100%, 640px);
  margin: 0 auto 16px;
}

.games-controls:has(#reset-game-search-control[hidden]) {
  grid-template-columns: minmax(220px, 275px) minmax(112px, 112px) 44px;
}

.games-controls input,
.games-controls select {
  width: 100%;
  min-height: 42px;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(#ffffff, #f5f9fd);
  color: var(--primary-dark);
  font: inherit;
  font-weight: 400;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.06);
}

.games-controls input:focus,
.games-controls select:focus {
  outline: none;
  border-color: #5f86a3;
  box-shadow: 0 0 0 2px rgba(95,134,163,0.14);
}

.games-controls .control-btn {
  min-height: 42px;
  padding: 8px 18px;
  border-radius: 8px;
  white-space: nowrap;
}

.games-advanced-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.games-advanced-control[hidden] {
  display: none;
}

.games-advanced-control .tooltip {
  bottom: 118%;
}

.games-icon-button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
}

.games-controls .games-icon-button {
  box-sizing: border-box;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px;
  padding: 0 !important;
}

.games-icon-button img {
  display: block;
  width: 20px;
  height: 20px;
  opacity: 0.82;
  filter: brightness(0) saturate(100%) invert(25%) sepia(28%) saturate(1061%) hue-rotate(164deg) brightness(92%) contrast(86%);
}

.games-controls .games-icon-button img {
  width: 20px !important;
  height: 20px !important;
  max-width: 20px;
  max-height: 20px;
}

.games-icon-button:hover img,
.games-icon-button:focus-visible img {
  opacity: 1;
}

@media (max-width: 640px) {
  .text.center-text {
    display: flex;
    flex-direction: column;
  }

  .games-title {
    order: 1;
  }

  .games-filter-toggle {
    appearance: none;
    -webkit-appearance: none;
    order: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    margin: 10px auto !important;
    margin-block: 10px !important;
    margin-inline: auto !important;
    padding: 6px 15px;
    border: 1px solid var(--button-border);
    border-radius: 10px;
    background: var(--button-bg);
    color: var(--button-text);
    box-shadow: var(--button-shadow);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
  }

  .games-filter-toggle:hover {
    border-color: var(--button-hover-border);
    background: var(--button-hover-bg);
    color: var(--button-hover-text);
    box-shadow: var(--button-hover-shadow);
  }

  .games-filter-toggle img {
    width: 18px;
    height: 18px;
    opacity: 0.82;
    filter: brightness(0) saturate(100%) invert(25%) sepia(28%) saturate(1061%) hue-rotate(164deg) brightness(92%) contrast(86%);
  }

  .games-filter-arrow {
    display: inline-block;
    font-size: 13px;
    line-height: 1;
    transition: transform 0.15s ease;
  }

  .games-filter-toggle[aria-expanded="true"] .games-filter-arrow {
    transform: rotate(180deg);
  }

  .games-controls {
    order: 3;
    display: none;
    grid-template-columns: minmax(0, 1fr) 44px 44px;
    width: min(100%, 312px);
    margin: 0 auto 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: linear-gradient(#f8fbff, #edf3f8);
    box-shadow: inset 0 1px 0 #fff, 0 2px 6px rgba(0,0,0,0.06);
  }

  .text.center-text > .tabs {
    order: 4;
    margin-top: 0;
    margin-bottom: 8px;
  }

  #tab-content {
    order: 5;
  }

  .games-controls:has(#reset-game-search-control[hidden]) {
    grid-template-columns: minmax(0, 1fr) 44px;
  }

  .games-controls.mobile-filters-open {
    display: grid;
  }

  .games-controls input {
    grid-column: 1 / -1;
  }

  .games-controls .control-btn:not(.games-icon-button) {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .games-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    max-width: 100%;
    width: 100%;
  }

  .game-card {
    max-width: none;
  }

  .tabs {
    gap: 12px;
    row-gap: 4px;
    overflow: visible;
    justify-content: center;
    flex-wrap: wrap;
    padding: 0 2px;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    flex: 0 0 auto;
    font-size: 16px;
  }
}

@media (min-width: 641px) and (max-width: 1100px) {
  .tabs {
    max-width: 720px;
    width: calc(100% - 40px);
    margin-left: auto;
    margin-right: auto;
  }

  .games-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    max-width: 720px;
    width: calc(100% - 40px);
  }

  .game-card {
    max-width: none;
  }
}

@media (max-width: 520px) {
  .games-controls {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
  }

  .games-controls:has(#reset-game-search-control:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) 44px 44px;
  }

  .games-controls input {
    grid-column: 1 / -1;
  }

  .games-controls select {
    min-width: 0;
  }

  .games-grid {
    grid-template-columns: 1fr;
  }

  .games-title {
    font-size: 26px;
  }

  .series-title {
    font-size: 20px;
  }

  .game-card img {
    height: auto;
  }

  .favorite-action {
    top: -10px;
    right: -10px;
  }
}
