*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3148;
  --accent: #6c63ff;
  --accent-dim: #4b44cc;
  --text: #e2e4f0;
  --text-muted: #7b7f9e;
  --danger: #e05c5c;
  --rating-neutral: #3a3d55;
  --rating-1: #cc2222;
  --rating-2: #c9a800;
  --rating-3: #1e8c1e;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
nav .brand { font-size: 1.1rem; font-weight: 700; color: var(--text); text-decoration: none; }
nav .spacer { flex: 1; }
nav a { color: var(--text-muted); font-size: 0.9rem; }
nav a:hover { color: var(--text); text-decoration: none; }

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.container--wide {
  max-width: 1440px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 { font-size: 1.6rem; margin-bottom: 1.25rem; }
h2 { font-size: 1.2rem; margin-bottom: 0.75rem; color: var(--text-muted); font-weight: 500; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

/* Forms */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.35rem; }
input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.8rem;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.15s;
  text-align: center;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #8b1a1a; color: #fff; }
.btn-danger:hover { background: #b22222; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-steam {
  background: #171a21;
  color: #c6d4df;
  border: 1px solid #4a6f8a;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Auth pages */
.auth-wrap {
  max-width: 380px;
  margin: 6rem auto;
  padding: 0 1rem;
}
.auth-wrap h1 { text-align: center; margin-bottom: 1.5rem; }

/* Error banner */
.error {
  background: #3b1f1f;
  border: 1px solid var(--danger);
  color: #f5a0a0;
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* Library */
.library-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 1.25rem;
  gap: 0.75rem;
}
.library-header h1 { margin: 0; font-size: 2.1rem; }

.library-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.add-game-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 420px;
  margin-bottom: 0;
}
.add-game-row input { flex: 1; }

#game-list { list-style: none; }

.game-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  transition: background 0.1s;
}
.game-row:hover { background: var(--surface2); }
.game-row--hidden { opacity: 0.5; }
.game-row--hidden:hover { opacity: 0.8; }
.game-name { flex: 0 0 220px; font-size: 0.95rem; }
.hidden-badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* List view rating buttons */
.rating-btns { display: flex; gap: 0.3rem; flex: 1; }
/* Grid view rating buttons */
.rating-btns-grid { display: flex; gap: 0.3rem; width: 100%; }
.rating-btn {
  flex: 1;
  height: 30px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--rating-neutral);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.1s;
}
.rating-btn:hover { border-color: var(--accent); }
.rating-btn.active-1 { background: var(--rating-1); border-color: var(--rating-1); color: #fff; }
.rating-btn.active-2 { background: var(--rating-2); border-color: var(--rating-2); color: #111; }
.rating-btn.active-3 { background: var(--rating-3); border-color: var(--rating-3); color: #fff; }

.remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
.remove-btn:hover { color: var(--danger); background: #2a1a1a; }

/* Groups list */
.group-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.6rem;
}
.group-card .group-name { font-weight: 500; font-size: 2rem; }

/* Group detail */
.invite-code {
  font-family: monospace;
  font-size: 1.4rem;
  letter-spacing: 0.25em;
  color: var(--accent);
  background: var(--surface2);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  display: inline-block;
}
/* Toggle switch */
.toggle-switch { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; }
.toggle-track {
  display: inline-flex;
  align-items: center;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle-track.on { background: var(--accent); border-color: var(--accent); }
.toggle-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}
.toggle-track.on .toggle-thumb { transform: translateX(18px); background: #fff; }
.toggle-label { font-size: 0.88rem; color: var(--text-muted); user-select: none; }

/* View toggle */
.view-toggle { display: flex; gap: 0.3rem; }
.view-btn {
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.view-btn:hover { border-color: var(--accent); color: var(--text); }
.view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Grid view */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(calc((100% - 4rem) / 5), 240px, calc(50% - 0.5rem)), 1fr));
  gap: 1rem;
}
.no-results-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 0;
  list-style: none;
}
.game-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}
.game-card:hover { border-color: var(--accent); }
.game-card--hidden { opacity: 0.5; }
.game-card--hidden:hover { opacity: 0.8; }
.game-card-art-link { display: block; }
.game-card-art-link:hover { opacity: 0.85; }
.game-card-img {
  width: 100%;
  aspect-ratio: 460 / 215;
  object-fit: cover;
  display: block;
}
.game-card-placeholder {
  width: 100%;
  aspect-ratio: 460 / 215;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 700;
  text-align: center;
  padding: 0.5rem;
  word-break: break-word;
}
.game-card-body {
  padding: 0.6rem 0.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.game-card-hide-btn {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.15s;
}
.game-card:hover .game-card-hide-btn { opacity: 1; }
.game-card-hide-btn:hover { background: rgba(180,40,40,0.85); color: #fff; }
.game-card-fav-btn {
  position: absolute;
  top: 0.3rem;
  left: 0.3rem;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.8rem;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.15s;
}
.game-card:hover .game-card-fav-btn { opacity: 1; }
.game-card-fav-btn:hover { background: rgba(0,0,0,0.75); color: gold; }
.game-card-fav-btn--active { opacity: 1 !important; color: gold; }
@keyframes shimmer-gold {
  0%, 100% { box-shadow: 0 0 6px 2px rgba(255, 215, 0, 0.5); border-color: rgba(255, 215, 0, 0.7); }
  50%       { box-shadow: 0 0 16px 5px rgba(255, 215, 0, 0.9); border-color: gold; }
}
.game-card--favorite {
  border: 2px solid gold;
  animation: shimmer-gold 4s ease-in-out infinite;
}
#fav-notification { position: fixed; top: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 1000; pointer-events: none; }
.fav-notify-msg {
  display: block;
  background: var(--surface);
  border: 1px solid gold;
  color: var(--text);
  padding: 0.67rem 1.47rem;
  border-radius: 6px;
  font-size: 1.2rem;
  white-space: nowrap;
  animation: fav-fade 5s ease forwards;
}
.game-card-title-hidden {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  user-select: none;
  font-size: 0.1px;
}

.game-card-title {
  flex: 1;
  font-size: 0.83rem;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.member-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.2rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Ranked list */
.ranked-list { list-style: none; }
.ranked-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
}
.ranked-item:nth-child(odd) { background: var(--surface2); }
.rank-num {
  width: 28px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.rank-name { flex: 1; }
.rank-score {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Action row */
.action-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

.htmx-indicator { display: none; }

/* Admin page */
.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.admin-section h2 { margin: 0 0 1rem; font-size: 1.1rem; }

.admin-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1.25rem;
  min-width: 120px;
  text-align: center;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.admin-search {
  width: 100%;
  max-width: 400px;
  padding: 0.5rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}
.admin-search:focus { outline: none; border-color: var(--accent); }

.admin-game-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.admin-game-name { flex: 1; min-width: 180px; }
.admin-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-weight: 600;
}
.badge--mp { background: #1a4a1a; color: var(--rating-3); }
.badge--sp { background: #3a1a1a; color: var(--rating-1); }
.badge--unknown { background: var(--surface2); color: var(--text-muted); }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.admin-table th {
  text-align: left;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
}
.admin-table td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

/* Smooth swap transition for game cards only */
#game-results { transition: opacity 0.05s ease; }
#game-section.htmx-swapping #game-results { opacity: 0; }
#game-section.htmx-settling #game-results { opacity: 0; }

/* Sort row */
.sort-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.sort-label { font-size: 0.85rem; color: var(--text-muted); }
.sort-order-btn { min-width: 2rem; font-size: 1rem; }

/* Library search row */
.search-row {
  display: flex;
  align-items: center;
  margin-bottom: 1.25rem;
}
.search-row__side {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.library-search {
  display: block;
  width: 100%;
  max-width: 420px;
  padding: 0.5rem 0.75rem;
  margin: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}
.library-search:focus {
  outline: none;
  border-color: var(--accent);
}
.library-search::placeholder {
  color: var(--text-muted);
}

.add-game-error { font-size: 0.85rem; color: var(--rating-1); }

/* Group game card */
.group-game-card { position: relative; }

.group-rank-badge {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  z-index: 1;
}

.group-score-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Group list triptych */
.group-card-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.6rem;
  background: var(--surface2);
}
.group-card-wrap .group-card {
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
  background: transparent;
}

.group-triptych {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.triptych-tile {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.triptych-tile:last-child { border-right: none; }
.triptych-tile a,
.triptych-tile > .triptych-placeholder { display: block; }
.triptych-tile img {
  width: 100%;
  aspect-ratio: 460 / 215;
  object-fit: cover;
  display: block;
}
.triptych-tile a:hover img { opacity: 0.85; }
.triptych-placeholder {
  width: 100%;
  aspect-ratio: 460 / 215;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-muted);
}
.triptych-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.group-list-code {
  font-family: monospace;
  font-size: 1.6rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
}
.group-list-code:hover { border-color: var(--accent); color: var(--text); }

.copy-toast {
  position: fixed;
  transform: translateX(-50%) translateY(-100%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  animation: toast-fade 1.5s ease forwards;
}
@keyframes toast-fade {
  0%   { opacity: 1; transform: translateY(0); }
  70%  { opacity: 1; transform: translateY(-4px); }
  100% { opacity: 0; transform: translateY(-8px); }
}
@keyframes fav-fade {
  0%, 75% { opacity: 1; }
  100%     { opacity: 0; }
}

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Nav: stack brand + links, hide username, shrink padding */
  nav {
    padding: 0.6rem 1rem;
    gap: 1rem;
    flex-wrap: wrap;
  }
  nav .spacer { display: none; }
  nav a[href="/profile"] { display: none; }
  nav form[action="/logout"] button { font-size: 0.75rem; padding: 0.25rem 0.6rem; }

  /* Containers: tighter horizontal padding */
  .container, .container--wide {
    padding: 1.25rem 0.75rem;
  }

  /* Library header */
  .library-header h1 { font-size: 1.5rem; }
  .library-controls { gap: 0.5rem; }
  .add-game-row { flex-wrap: wrap; }
  .add-game-row input { flex: 1 1 0; min-width: 0; }

  /* Search row: search full-width on top, hide-rated + view toggle on one row below */
  .search-row { flex-wrap: wrap; gap: 0.6rem; }
  .library-search { order: -1; width: 100%; max-width: 100%; }
  .search-row__side { flex: 1; }
  .search-row__side:first-child { justify-content: flex-start; }
  .search-row__side:last-child  { justify-content: flex-end; }
  .view-toggle { justify-content: flex-end; }

  /* Game grid: exactly 2 columns on mobile */
  .game-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }

  /* Rating buttons: smaller text */
  .rating-btn { font-size: 0.7rem; }

  /* Group cards */
  .group-card .group-name { font-size: 1.2rem; }
  .group-list-code { font-size: 1rem; }
  .group-triptych { gap: 0.4rem; }

  /* Group detail header */
  .groups-detail-header h1 { font-size: 1.4rem; }

  /* Auth wrap */
  .auth-wrap h1 { font-size: 1.6rem; }

  /* Action rows (create/join buttons) */
  .action-row { flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
  .action-row .btn { flex: 1 1 120px; text-align: center; }
}

/* Very small screens (≤480px): tighter nav */
@media (max-width: 480px) {
  nav { gap: 0.75rem; }
}
