/* =========================================================
   NAPL — SHARED UI COMPONENTS
   Back Button, Search, Game Cards, Multi-Game Apps
   ========================================================= */

/* Shared Sub-View Back Button */
.back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.back-button:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--accent);
}

.back-button:active {
  transform: scale(0.97);
}

/* Global Search */
.search-container {
  position: relative;
  max-width: 640px;
  margin: 0 auto 24px;
}

.search-container:not([hidden]) {
  animation: napl-search-reveal 180ms var(--ease-out) backwards;
}

#search,
#category-search {
  width: 100%;
  min-height: 46px;
  padding: 10px 16px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-strong);
  font-size: 15px;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

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

#search:focus,
#category-search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-1);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 80;
  background: var(--surface-2);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-popover);
  transform-origin: top center;
}

.search-results:not([hidden]) {
  animation: napl-search-dropdown-in 160ms var(--ease-out) backwards;
}

.search-result {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 16px;
  color: var(--text-strong);
  font-size: 14px;
  font-weight: 500;
  border-bottom: 1px solid var(--border-subtle);
  transition:
    background-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    padding-left var(--duration-fast) var(--ease-out);
}

.search-result.is-entering {
  animation: napl-card-enter 160ms var(--ease-out) backwards;
  animation-delay: calc(min(var(--enter-index, 0), 5) * 16ms);
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result:hover {
  background: var(--surface-3);
  color: var(--accent);
  padding-left: 20px;
}

/* Game Card — Detailed List */
.home-game {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  display: flex;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  box-shadow: var(--shadow-card);
  transition:
    transform var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

@supports ((-webkit-mask-composite: xor) or (mask-composite: exclude)) {
  .home-game::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 3;
    padding: 1.5px;
    border-radius: calc(var(--radius-md) - 1px);
    pointer-events: none;
    background: radial-gradient(
      210px circle at var(--spot-x, 16%) var(--spot-y, 0%),
      rgba(110, 231, 160, 0.96),
      rgba(245, 196, 81, 0.72) 34%,
      rgba(110, 231, 160, 0.24) 64%,
      transparent 100%
    );
    -webkit-mask:
      linear-gradient(#fff 0 0) content-box,
      linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask:
      linear-gradient(#fff 0 0) content-box,
      linear-gradient(#fff 0 0);
    mask-composite: exclude;
    opacity: 0.34;
    transition: opacity var(--duration-fast) var(--ease-out);
  }

  html[data-theme="light"] .home-game::before {
    background: radial-gradient(
      210px circle at var(--spot-x, 16%) var(--spot-y, 0%),
      rgba(15, 138, 107, 0.92),
      rgba(217, 119, 6, 0.68) 34%,
      rgba(15, 92, 82, 0.22) 64%,
      transparent 100%
    );
    opacity: 0.28;
  }

  .home-game:hover::before,
  .home-game:focus-visible::before {
    opacity: 1;
  }
}

.home-game.is-entering,
.multi-game-app-card.is-entering {
  animation: napl-card-enter 210ms var(--ease-out) backwards;
  animation-delay: calc(min(var(--enter-index, 0), 10) * 18ms);
}

.home-game:hover,
.home-game:focus-visible {
  transform: translateY(-2px);
  background: var(--surface-2);
  border-color: rgba(110, 231, 160, 0.45);
  box-shadow:
    0 12px 26px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(110, 231, 160, 0.14);
}

html[data-theme="light"] .home-game:hover,
html[data-theme="light"] .home-game:focus-visible {
  border-color: rgba(15, 92, 82, 0.38);
  box-shadow:
    0 10px 22px rgba(11, 31, 28, 0.11),
    0 0 0 1px rgba(15, 92, 82, 0.08);
}

.home-game:active {
  transform: scale(0.99);
}

.home-game-cover-container {
  position: relative;
  z-index: 2;
  flex: 0 0 64px;
  width: 64px;
  height: fit-content;
  min-height: 88px;
  align-self: center;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.24);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

html[data-theme="light"] .home-game-cover-container {
  border-color: rgba(15, 92, 82, 0.18);
  box-shadow: 0 4px 10px rgba(11, 31, 28, 0.08);
}

.home-game:hover .home-game-cover-container,
.home-game:focus-visible .home-game-cover-container {
  border-color: var(--border-strong);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

html[data-theme="light"] .home-game:hover .home-game-cover-container,
html[data-theme="light"] .home-game:focus-visible .home-game-cover-container {
  box-shadow: 0 6px 14px rgba(11, 31, 28, 0.12);
}

.home-game-cover-container.is-loaded {
  min-height: 0;
}

.home-game-cover-container.cover-unavailable::after {
  content: "NAPL";
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.home-game-cover {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  height: auto !important;
  max-height: none;
  aspect-ratio: auto;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 220ms var(--ease-out);
}

.home-game:hover .home-game-cover,
.home-game:focus-visible .home-game-cover {
  transform: scale(1.06);
}

@keyframes napl-card-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes napl-search-reveal {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes napl-search-dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .search-container:not([hidden]),
  .search-results:not([hidden]),
  .search-result.is-entering,
  .home-game.is-entering,
  .multi-game-app-card.is-entering {
    animation: none !important;
  }

  .back-button:active,
  .home-game:hover,
  .home-game:focus-visible,
  .home-game:hover .home-game-cover,
  .home-game:focus-visible .home-game-cover,
  .home-game:active {
    transform: none;
  }
}

.home-game-content {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.home-game-rank {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.home-game-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.home-game-metadata {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-game-port {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Multi-Game Apps */
#game-list:has(.multi-game-app-card) {
  align-items: start;
}

.game {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  padding: 18px;
  background:
    radial-gradient(circle at top right, rgba(110, 231, 160, 0.08), transparent 62%),
    var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.multi-game-app-card:hover {
  border-color: var(--border-medium);
  box-shadow: var(--shadow-card);
  transform: translateY(-1px);
}

.multi-game-app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.game-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-strong);
  min-width: 0;
  overflow-wrap: anywhere;
}

.multi-game-app-badge {
  flex-shrink: 0;
  padding: 4px 8px;
  background: var(--accent-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.multi-game-app-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.multi-game-app-preview {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.games-using-app {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.games-using-app-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
  text-align: left;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.games-using-app-toggle:hover,
.games-using-app.is-open .games-using-app-toggle {
  background: var(--surface-3);
  border-color: var(--border-medium);
  color: var(--accent);
}

.games-using-app-toggle-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.games-using-app-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.games-using-app-toggle-title {
  min-width: 0;
}

.games-using-app-toggle-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.games-using-app-toggle-count {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.games-using-app-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: transform var(--duration-fast) var(--ease-out);
}

.games-using-app.is-open .games-using-app-arrow {
  transform: rotate(180deg);
}

.games-using-app-drawer {
  margin-top: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
}

.games-using-app-drawer[hidden] {
  display: none;
}

.games-using-app-filter {
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-2);
}

.games-using-app-filter-input {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  background: var(--surface-1);
  font-size: 12.5px;
  color: var(--text-main);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out);
}

.games-using-app-filter-input::placeholder {
  color: var(--text-muted);
}

.games-using-app-filter-input:focus {
  border-color: var(--border-strong);
}

.games-using-app-empty {
  padding: 14px 10px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}

.games-using-app-empty[hidden] {
  display: none;
}

.games-using-app-viewport {
  position: relative;
  background: var(--surface-2);
}

.games-using-app-viewport::before,
.games-using-app-viewport::after {
  content: "";
  position: absolute;
  left: 0;
  right: 8px;
  height: 26px;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
  transition: opacity var(--duration-fast) var(--ease-out);
}

.games-using-app-viewport::before {
  top: 0;
  background: linear-gradient(to bottom, var(--surface-2) 15%, transparent 100%);
}

.games-using-app-viewport::after {
  bottom: 0;
  background: linear-gradient(to top, var(--surface-2) 15%, transparent 100%);
}

.games-using-app-viewport.has-top-fade::before {
  opacity: 1;
}

.games-using-app-viewport.has-bottom-fade::after {
  opacity: 1;
}

.games-using-app-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 232px;
  padding: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.games-using-app-list::-webkit-scrollbar {
  width: 7px;
}

.games-using-app-list::-webkit-scrollbar-track {
  background: var(--surface-1);
  border-radius: 999px;
  margin: 6px 0;
}

.games-using-app-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.games-using-app-list::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.games-using-app-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.games-using-app-item:hover {
  background: var(--surface-3);
  border-color: var(--border-medium);
  color: var(--accent);
}

.games-using-app-item-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.games-using-app-item-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.games-using-app-item-year {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.games-using-app-item-arrow {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.games-using-app-item:hover .games-using-app-item-arrow {
  color: var(--accent);
  transform: translateX(2px);
}

@media (max-width: 480px) {
  .game {
    padding: 14px;
    gap: 8px;
  }

  .game-name {
    font-size: 16px;
  }

  .games-using-app-list {
    max-height: 210px;
  }
}
