/* =========================================================
   Components — Game cards, prices, loading, states
   ========================================================= */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: var(--space-xl);
  padding-block: var(--space-lg);
}

/* Tighter spacing on phones so more of the list is visible. */
@media (max-width: 768px) {
  .game-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
    padding-block: var(--space-md);
  }
}

/* ---- terminal card ---- */
.game-card {
  position: relative;
  min-height: 100%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  transition: border-color var(--transition), background var(--transition);
}

.game-card:hover,
.game-card:focus-within {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.game-card__link {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: var(--space-sm);
}

/* corner brackets */
.game-card__corner {
  position: absolute;
  width: 12px;
  height: 12px;
  z-index: 3;
  border-color: var(--border-strong);
  border-style: solid;
  border-width: 0;
  transition: border-color var(--transition);
  pointer-events: none;
}
.game-card__corner--tl { top: 4px; left: 4px; border-top-width: 2px; border-left-width: 2px; }
.game-card__corner--tr { top: 4px; right: 4px; border-top-width: 2px; border-right-width: 2px; }
.game-card__corner--bl { bottom: 4px; left: 4px; border-bottom-width: 2px; border-left-width: 2px; }
.game-card__corner--br { bottom: 4px; right: 4px; border-bottom-width: 2px; border-right-width: 2px; }
.game-card:hover .game-card__corner { border-color: var(--accent-hover); }

/* head row: ■ ───────── ‹ نوع [NN] */
.game-card__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.game-card__bullet { color: var(--text-secondary); }
.game-card__head-line {
  flex: 1;
  height: 0;
  border-top: 1px dashed var(--border-dash);
}
.game-card__head-label { color: var(--text-secondary); white-space: nowrap; }

.game-card__media {
  position: relative;
  overflow: hidden;
  aspect-ratio: 460 / 215;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

.game-card__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.62) contrast(1.02) brightness(0.96);
  transition: filter var(--transition-slow), transform var(--transition-slow);
}

.game-card:hover .game-card__image {
  filter: saturate(1) contrast(1.02);
  transform: scale(1.03);
}

.game-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-sm) var(--space-sm);
}

.game-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.game-card__platform { color: var(--text-secondary); }

.game-card__title {
  display: -webkit-box;
  min-height: 2.6em;
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.game-card__desc {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.6;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.game-card__desc.is-note { color: var(--text-primary); }
.game-card__desc.is-note::before {
  content: '› ';
  color: var(--text-muted);
}

.game-card__footer {
  display: flex;
  align-items: stretch;
  gap: var(--space-sm);
  margin-top: auto;
  padding-top: var(--space-sm);
}

.game-card__cta {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-family: var(--font-ar);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
}
.game-card:hover .game-card__cta { background: var(--accent); color: #0a0a0a; }

.game-card__score,
.game-card__time {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  line-height: 1.15;
}
.score__label, .time__label { font-size: 0.58rem; color: var(--text-muted); }
.score__val { font-size: var(--text-md); font-weight: 700; color: var(--text-primary); }
.score__max { font-size: 0.6rem; color: var(--text-muted); }
.score__na { color: var(--text-muted); }

/* playtime box — highlighted so "hours to finish" reads at a glance */
.game-card__time {
  background: var(--accent);
  border-color: var(--accent);
}
.game-card__time .time__label { color: #2a2a2a; }
.time__val { font-size: var(--text-md); font-weight: 700; color: #0a0a0a; white-space: nowrap; }
.time__unit { font-size: 0.58rem; color: #2a2a2a; }

.game-card__footer { flex-wrap: wrap; }
.game-card__cta { min-width: 0; }

.game-card__price {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  min-height: 28px;
  font-family: var(--font-mono);
}

.price--original {
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-decoration: line-through;
}

.price--final {
  color: var(--text-primary);
  font-size: var(--text-md);
  font-weight: 700;
}

.price--free {
  display: inline-flex;
  align-items: center;
  color: #0a0a0a;
  background: var(--free-bg);
  font-size: var(--text-sm);
  font-weight: 700;
  padding: 0.1rem 0.5rem;
}

.price--unavailable { color: var(--text-muted); }

.discount-badge {
  display: inline-flex;
  align-items: center;
  color: #0a0a0a;
  background: var(--discount-bg);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.1rem 0.4rem;
}

.game-card__genres {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.genre-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  white-space: nowrap;
}
.genre-chip::before { content: ''; }

.genre-chip--arabic {
  color: #0a0a0a;
  background: var(--accent);
  border-color: transparent;
  font-family: var(--font-ar);
}

/* keep formatStats() output usable if referenced elsewhere */
.game-card__stats { display: none; }

.game-card--skeleton {
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  pointer-events: none;
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.4s infinite ease-in-out;
}

.skeleton--image {
  aspect-ratio: 460 / 215;
  width: 100%;
  border-radius: 0;
}

.skeleton--title {
  height: 1.2em;
  width: 90%;
  margin-bottom: var(--space-sm);
}

.skeleton--title-short {
  height: 1.2em;
  width: 60%;
}

.skeleton--price {
  height: 1.4em;
  width: 45%;
  margin-top: auto;
}

.skeleton--genres {
  height: 1em;
  width: 70%;
  margin-top: var(--space-xs);
}

@keyframes skeleton-pulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding: var(--space-2xl) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}

.error-state[hidden],
.loading-state[hidden],
[hidden] {
  display: none !important;
}

.error-state__icon {
  font-size: 3rem;
}

.error-state__title {
  font-size: var(--text-xl);
  font-weight: 800;
}

.error-state__message {
  max-width: 420px;
  color: var(--text-secondary);
}

.error-state__message code {
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--accent-hover);
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--font-en);
}

.error-state__retry {
  min-height: 44px;
  padding-inline: var(--space-xl);
  border-radius: var(--radius-pill);
  color: #061018;
  background: var(--accent);
  font-size: var(--text-base);
  font-weight: 800;
  transition: transform var(--transition), background var(--transition);
}

.error-state__retry:hover {
  transform: translateY(-2px);
  background: var(--accent-hover);
}

/* ---- note badge on card ---- */
/* note badge handled via head label now; keep cards clean */
.game-card__note-badge { display: none; }

.game-card.has-note { border-color: var(--border-strong); }
.game-card.has-note .game-card__corner { border-color: var(--accent-soft); }

/* ---- game detail / note modal ---- */
.game-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

.game-modal[hidden] { display: none; }

.game-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  animation: modal-fade 0.16s ease;
}

.game-modal__dialog {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px var(--bg-primary), 0 0 0 5px var(--border-color);
  animation: modal-pop 0.18s ease;
}

.game-modal__close {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  z-index: 3;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-strong);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  cursor: pointer;
}

.game-modal__close:hover { background: var(--accent); color: #0a0a0a; }

.game-modal__media {
  aspect-ratio: 460 / 215;
  overflow: hidden;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}
.game-modal__image { width: 100%; height: 100%; object-fit: cover; display: block; filter: contrast(1.02); }

.game-modal__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-lg);
}

.game-modal__title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
}

.game-modal__stats { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.game-modal__stats .stat {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-primary);
}

.game-modal__note {
  border: 1px solid var(--border-strong);
  border-inline-start-width: 3px;
  background: rgba(255, 255, 255, 0.03);
  padding: var(--space-md);
}

.game-modal__note[hidden] { display: none; }

.game-modal__note-label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
}

.game-modal__note-text {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: 1.8;
  white-space: pre-wrap;
}

.game-modal__genres { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.game-modal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding-top: var(--space-sm);
  border-top: 1px dashed var(--border-dash);
}

.game-modal__steam {
  display: inline-flex;
  align-items: center;
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border-strong);
  background: var(--accent);
  color: #0a0a0a;
  font-weight: 700;
  font-size: var(--text-sm);
  transition: background var(--transition);
}

.game-modal__steam:hover { background: var(--accent-hover); }
.game-modal__steam[hidden] { display: none; }

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
