/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0e1117;
  --surface: #161b22;
  --surface-hover: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --star-filled: #f0b400;
  --star-empty: #30363d;
  --danger: #f85149;
  --success: #3fb950;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Navbar ── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.user-info {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.current-user {
  padding: 0.4rem 1rem;
  background: var(--accent);
  border-radius: 20px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

.logout-btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.logout-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ── Login Page ── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 2rem;
  line-height: 1.3;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-input {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  text-align: center;
  transition: border-color 0.15s;
}

.login-input:focus {
  border-color: var(--accent);
}

.login-input::placeholder {
  color: var(--text-muted);
}

.login-btn {
  padding: 0.75rem;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-btn:hover {
  opacity: 0.9;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
}

.login-success {
  color: var(--success);
  font-size: 0.9rem;
}

.login-back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  text-align: center;
  transition: color 0.15s;
}

.login-back:hover {
  color: var(--text);
}

.current-user {
  text-decoration: none;
}

/* ── Container ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Search ── */
.search-wrapper {
  position: relative;
  margin-bottom: 1.5rem;
}

#search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus {
  border-color: var(--accent);
}

#search-input::placeholder {
  color: var(--text-muted);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}

.search-results.visible {
  display: block;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 0.9rem;
}

.search-item:hover {
  background: var(--surface-hover);
}

.search-item img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.search-item.no-results {
  color: var(--text-muted);
  cursor: default;
  justify-content: center;
}

.search-item.no-results:hover {
  background: transparent;
}

/* ── Game Grid ── */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

/* ── Game Card ── */
.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}

.game-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.game-card {
  position: relative;
}

.card-image {
  display: block;
  height: 160px;
  background-size: cover;
  background-position: center;
  position: relative;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.priority-badge {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--star-filled);
}

.priority-badge.empty {
  color: var(--text-muted);
}

.delete-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: color 0.15s, transform 0.15s;
}

.delete-btn:hover {
  color: var(--danger);
  transform: scale(1.08);
}

.card-body {
  padding: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* ── View Title + Action Buttons ── */
.view-title {
  margin: 0 0 1rem 0;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
}

.view-title:empty {
  display: none;
}

.complete-btn,
.restore-btn {
  position: absolute;
  top: 0.6rem;
  right: 2.6rem; /* sit to the left of the delete button */
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
  z-index: 2;
  line-height: 1;
}

.complete-btn:hover {
  background: var(--success, #2ea043);
  transform: scale(1.08);
}

.restore-btn {
  font-size: 1.1rem;
}

.restore-btn:hover {
  background: var(--accent, #58a6ff);
  transform: scale(1.08);
}

/* In the trash view there's no delete button, so restore takes the primary slot */
.game-card.is-deleted .restore-btn {
  right: 0.6rem;
}

.status-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  margin-bottom: 0.6rem;
}

.status-info strong {
  color: var(--text);
}

.game-card.is-deleted .card-image {
  filter: grayscale(0.4) brightness(0.85);
}

/* ── Controls Bar (Filter + Sort) ── */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex: 1;
}

.filter-btn {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sort-select {
  padding: 0.3rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.sort-select:focus {
  border-color: var(--accent);
}

.empty-filter-msg {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
  grid-column: 1 / -1;
}

/* ── Release Badge ── */
.release-badge {
  position: absolute;
  bottom: 0.6rem;
  right: 0.6rem;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
}

.release-badge.coming-soon {
  color: #f0b400;
}

.release-badge.released {
  color: var(--text-muted);
}

/* ── Price Section ── */
.price-section {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  min-height: 1.2rem;
}

.price-loading {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.price-free {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--success);
}

.price-normal {
  font-size: 0.85rem;
  color: var(--text);
}

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

.price-sale {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--success);
}

.price-discount {
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--success);
  color: #fff;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* ── Ratings ── */
.card-ratings {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rating-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rating-user {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 50px;
}

.stars {
  display: flex;
  gap: 2px;
}

/* ── Half-star system ── */
.star-wrap {
  position: relative;
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  user-select: none;
}

.star-icon {
  font-size: 1.1rem;
  color: var(--star-empty);
  transition: color 0.1s;
  display: block;
  line-height: 1;
}

.star-icon.full {
  color: var(--star-filled);
}

.star-icon.half {
  position: relative;
  display: inline-block;
  color: var(--star-empty);
}

.star-icon.half::before {
  content: "★";
  position: absolute;
  left: 0;
  top: 0;
  width: 50%;
  overflow: hidden;
  color: var(--star-filled);
}

/* clickable half-overlays */
.star-half {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  cursor: pointer;
  z-index: 1;
}

.star-half.left  { left: 0; }
.star-half.right { right: 0; }

/* static display stars (non-interactive) */
.star-icon:not(.star-wrap .star-icon) {
  font-size: 1.1rem;
}

/* ── Activity Log ── */
.page-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.activity-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-hover);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.activity-content {
  flex: 1;
  font-size: 0.9rem;
}

.activity-game {
  display: inline;
  color: var(--accent);
  margin-left: 0.3rem;
}

.activity-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.error {
  color: var(--danger);
  text-align: center;
  padding: 1rem;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .navbar {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .nav-links { order: 3; width: 100%; }
  .user-switcher { order: 2; }
  .game-grid {
    grid-template-columns: 1fr;
  }
}
