/**
 * Hub-only layout. Shared tracker tokens and components come from
 * js/shared/collection-tracker/ui/styles.css. Card structure mirrors the main
 * home page (.tcg-game-card / .tcg-grid) so the hub feels like the same system.
 *
 * House rules: flat panel surfaces, no left-edge accent stripes, no ALL-CAPS or
 * letter-spaced labels, no status pills, copy wraps rather than clipping.
 */

.hub {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3.5rem;
}

:where(.hub) :where(h1, h2, h3) {
  margin: 0;
  line-height: 1.3;
}

:where(.hub) p {
  margin: 0;
}

:where(.hub) ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

:where(.hub) a {
  color: inherit;
  text-decoration: none;
}

.hub__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.15rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.hub__title {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 62ch;
}

.hub__title h1 {
  font-size: 1.75rem;
  color: var(--text);
}

.hub__eyebrow {
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
}

.hub__section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 2rem;
}

.hub__account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
}

.hub__account p {
  margin-top: 0.25rem;
  max-width: 62ch;
}

.hub__sectionhead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.hub__sectionmeta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.hub__games-note {
  margin-top: -0.35rem;
  max-width: 62ch;
}

.hub__manage {
  min-height: 44px;
  min-width: 44px;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-sec);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.hub__manage:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--card);
}

/* Equal-width action button rows (card footers + hidden games). */
.hub-game__actions,
.hub__hidden-actions {
  display: flex;
  flex: 1 1 auto;
  align-items: stretch;
  gap: 0.625rem;
  min-width: 0;
}

.hub-game__actions .ct-btn,
.hub__hidden-actions .ct-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}

.hub-game__actions .ct-btn:not(.ct-btn--primary),
.hub__hidden-actions .ct-btn:not(.ct-btn--primary) {
  border-color: var(--border);
  background: var(--panel);
  color: var(--text-sec);
}

.hub-game__actions .ct-btn:not(.ct-btn--primary):hover:not(:disabled),
.hub__hidden-actions .ct-btn:not(.ct-btn--primary):hover:not(:disabled) {
  border-color: var(--border-hover);
  color: var(--text);
  background: var(--card);
}

.hub__hidden-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  overflow: hidden;
}

.hub__hidden-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.95rem 1rem;
  cursor: pointer;
  list-style: none;
}

.hub__hidden-summary::-webkit-details-marker {
  display: none;
}

.hub__hidden-summary::before {
  content: '▸';
  margin-right: 0.55rem;
  color: var(--muted);
  transition: transform 0.15s;
}

.hub__hidden-panel[open] > .hub__hidden-summary::before {
  transform: rotate(90deg);
}

.hub__hidden-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--border);
}

.hub__hidden-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  transition: background 0.15s;
}

.hub__hidden-item:hover {
  background: color-mix(in srgb, var(--card) 92%, var(--primary) 8%);
}

.hub__hidden-item:last-child {
  border-bottom: 0;
}

.hub__hidden-info {
  display: flex;
  flex: 1 1 140px;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.hub__hidden-info strong {
  font-size: 0.92rem;
  font-weight: 600;
}

.hub__hidden-actions {
  flex: 1 1 240px;
  max-width: 100%;
}

/* Adaptive grid: column count is set from JS via data-visible-count (1-8). */
.hub__grid {
  display: grid;
  gap: 1.5rem;
}

.hub__hidden {
  margin-top: 0.15rem;
}

@media (min-width: 1200px) {
  .hub__grid:not([data-visible-count]) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='1'] {
    grid-template-columns: minmax(0, 420px);
    justify-content: center;
  }

  .hub__grid[data-visible-count='2'] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 720px;
    margin-inline: auto;
  }

  .hub__grid[data-visible-count='3'] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='4'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* 3 + 2, second row centered */
  .hub__grid[data-visible-count='5'] {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='5'] > .hub-game {
    grid-column: span 2;
  }

  .hub__grid[data-visible-count='5'] > .hub-game:nth-child(4) {
    grid-column: 2 / span 2;
  }

  .hub__grid[data-visible-count='5'] > .hub-game:nth-child(5) {
    grid-column: 4 / span 2;
  }

  .hub__grid[data-visible-count='6'] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* 4 + 3, second row centered */
  .hub__grid[data-visible-count='7'] {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='7'] > .hub-game {
    grid-column: span 2;
  }

  .hub__grid[data-visible-count='7'] > .hub-game:nth-child(5) {
    grid-column: 2 / span 2;
  }

  .hub__grid[data-visible-count='7'] > .hub-game:nth-child(6) {
    grid-column: 4 / span 2;
  }

  .hub__grid[data-visible-count='7'] > .hub-game:nth-child(7) {
    grid-column: 6 / span 2;
  }

  .hub__grid[data-visible-count='8'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.hub-game {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.15s;
}

.hub-game:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 10px 30px rgba(0, 179, 55, 0.15);
}

.hub-game__banner {
  position: relative;
  flex: 0 0 auto;
  height: 160px;
  min-height: 160px;
  background-color: var(--panel);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem 1.15rem;
  content-visibility: auto;
}

.hub-game__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.25) 100%);
  pointer-events: none;
}

.hub-game__title {
  position: relative;
  z-index: 1;
  margin: 0;
  width: 100%;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  text-align: center;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.85);
  overflow-wrap: anywhere;
}

.hub-game__panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.85rem;
  min-height: 0;
}

.hub-game__meta {
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.hub-game__content {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.85rem;
  min-height: 0;
}

.hub-game__stats {
  display: grid;
  flex: 1 1 140px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 0.75rem;
  min-width: 0;
}

.hub-game__stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.hub-game__stat strong {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.hub-game__stat span {
  color: var(--muted);
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}

/* Hub CTAs use site primary green, not per-game accent on each tile. */
.hub-game .ct-btn--primary,
.hub__hidden-actions .ct-btn--primary {
  border-color: transparent;
  background: var(--primary);
  color: #000;
}

.hub-game .ct-btn--primary:hover:not(:disabled),
.hub__hidden-actions .ct-btn--primary:hover:not(:disabled) {
  border-color: transparent;
  background: var(--primary-h);
  color: #000;
}

.hub-game .ct-btn--primary:focus-visible,
.hub__hidden-actions .ct-btn--primary:focus-visible {
  outline: 2px solid var(--primary-h);
  outline-offset: 2px;
}

.hub-game__empty {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.hub-game__empty strong {
  font-size: 0.92rem;
}

.hub-game__catalog {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem 0.65rem;
}

.hub-game__catalog-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.hub-game__catalog-stat strong {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hub-game__catalog-stat span {
  color: var(--muted);
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}

.hub-game__progress {
  width: 100%;
}

.hub-game__progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.hub-game__progress-fill {
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.25s ease;
}

.hub-game__content > .hub-game__catalog,
.hub-game__content > .hub-game__progress {
  flex: 1 1 100%;
  width: 100%;
}

.hub-game__content > .hub-game__stats {
  flex: 1 1 100%;
  width: 100%;
}

.hub-game__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.625rem;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.hub-game__foot > .ct-muted {
  flex: 1 1 140px;
  align-self: center;
  min-width: 0;
}

.hub-game__foot > .hub-game__actions {
  flex: 1 1 200px;
  min-width: min(100%, 220px);
}

.hub-game__foot > .hub-game__actions:only-child {
  flex: 1 1 100%;
  width: 100%;
}

.hub-game__error {
  color: var(--warn);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.hub__foot {
  padding-top: 1.15rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
}

@media (min-width: 769px) and (max-width: 1199px) {
  .hub__grid:not([data-visible-count]) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='1'] {
    grid-template-columns: minmax(0, 420px);
    justify-content: center;
  }

  .hub__grid[data-visible-count='2'],
  .hub__grid[data-visible-count='4'],
  .hub__grid[data-visible-count='6'],
  .hub__grid[data-visible-count='8'] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* 2 + 1, last card centered */
  .hub__grid[data-visible-count='3'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='3'] > .hub-game {
    grid-column: span 2;
  }

  .hub__grid[data-visible-count='3'] > .hub-game:nth-child(3) {
    grid-column: 2 / span 2;
  }

  /* 2 + 2 + 1, last card centered */
  .hub__grid[data-visible-count='5'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='5'] > .hub-game {
    grid-column: span 2;
  }

  .hub__grid[data-visible-count='5'] > .hub-game:nth-child(5) {
    grid-column: 2 / span 2;
  }

  /* 2 + 2 + 2 + 1, last card centered */
  .hub__grid[data-visible-count='7'] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hub__grid[data-visible-count='7'] > .hub-game {
    grid-column: span 2;
  }

  .hub__grid[data-visible-count='7'] > .hub-game:nth-child(7) {
    grid-column: 2 / span 2;
  }
}

@media (max-width: 768px) {
  .hub {
    padding: 1.25rem 0.85rem 3rem;
  }

  .hub__title h1 {
    font-size: 1.5rem;
  }

  .hub__grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .hub-game__banner {
    height: 140px;
    min-height: 140px;
  }

  .hub-game__catalog {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hub__hidden-item {
    flex-direction: column;
    align-items: stretch;
  }

  .hub__hidden-actions {
    flex: 1 1 100%;
    width: 100%;
  }
}
