:root {
  color-scheme: light;
  --page: #eef5ff;
  --surface: #ffffff;
  --surface-soft: #f7fbff;
  --surface-strong: #dfeeff;
  --text: #17314f;
  --muted: #657992;
  --line: #c8dcf4;
  --brand: #6ea5e8;
  --brand-dark: #285f9f;
  --brand-deep: #164a83;
  --brand-soft: #e3f0ff;
  --accent: #f6b900;
  --cta: #4d8fd8;
  --cta-dark: #2d6fb6;
  --shadow: 0 18px 50px rgba(54, 104, 161, 0.15);
  --shadow-soft: 0 10px 28px rgba(54, 104, 161, 0.1);
  --focus: 0 0 0 4px rgba(110, 165, 232, 0.26);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  line-height: 1.5;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 255, 255, 0.95) 0 22%, transparent 44%),
    linear-gradient(180deg, #f7fbff 0%, var(--page) 42%, #f8fbff 100%);
}

body.lightbox-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 0;
  box-shadow: var(--focus);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--brand-deep);
  color: white;
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-72px);
  transition: transform 160ms var(--ease);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

.page-shell {
  width: min(1120px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.product-category,
.result-summary,
.empty-state p {
  color: var(--muted);
}

.toolbar {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  transition: border-color 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}

.search-box:focus-within {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: var(--focus);
}

.search-icon {
  position: relative;
  width: 18px;
  height: 18px;
  margin-right: 10px;
  color: var(--brand);
}

.search-icon::before,
.search-icon::after {
  content: "";
  position: absolute;
  display: block;
}

.search-icon::before {
  inset: 1px 5px 5px 1px;
  border: 2px solid currentColor;
  border-radius: 999px;
}

.search-icon::after {
  width: 8px;
  height: 2px;
  right: 0;
  bottom: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(45deg);
  transform-origin: center;
}

#product-search {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
}

#product-search::placeholder {
  color: #8297ae;
}

.category-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 3px 0 6px;
  scrollbar-width: none;
}

.category-row::-webkit-scrollbar {
  display: none;
}

.category-chip {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms var(--ease), background 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease), box-shadow 160ms var(--ease);
}

.category-chip:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.category-chip[aria-pressed="true"] {
  border-color: var(--brand-dark);
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: white;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(77, 143, 216, 0.26);
}

.category-chip:active {
  transform: scale(0.98);
}

.result-summary {
  margin: 16px 2px 10px;
  font-weight: 700;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  transition: opacity 140ms var(--ease), transform 140ms var(--ease);
}

.product-grid.is-updating {
  opacity: 0.45;
  transform: translateY(4px);
}

.product-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  animation: card-enter 260ms var(--ease) both;
  animation-delay: var(--delay, 0ms);
  transition: transform 160ms var(--ease), border-color 160ms var(--ease), box-shadow 160ms var(--ease);
  view-transition-name: none;
}

.product-card:hover {
  transform: translateY(-3px);
  border-color: rgba(110, 165, 232, 0.7);
  box-shadow: 0 18px 38px rgba(54, 104, 161, 0.18);
}

.product-card:hover .product-image {
  transform: scale(1.025);
}

.product-card:active {
  transform: translateY(-1px) scale(0.99);
}

.image-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--surface-strong);
}

.image-button {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.product-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 240ms var(--ease);
}

.image-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--brand);
  font-size: 2rem;
  font-weight: 900;
}

.image-button[hidden] + .image-fallback {
  display: grid;
}

.product-content {
  display: grid;
  grid-template-rows: auto minmax(48px, auto) auto auto;
  gap: 9px;
  min-width: 0;
  padding: 12px;
}

.product-category {
  margin: 0;
  color: var(--brand-dark);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.product-name {
  display: -webkit-box;
  min-height: 48px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.32;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.product-name-link {
  color: inherit;
  text-decoration: none;
}

.product-name-link:hover {
  color: var(--brand-dark);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.product-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rating-wrap {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
}

.star-rating {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 2px;
}

.star {
  position: relative;
  display: inline-block;
  width: 16px;
  height: 16px;
  overflow: hidden;
  background: #d8dfdb;
  clip-path: polygon(50% 0%, 61% 34%, 97% 34%, 68% 55%, 79% 90%, 50% 69%, 21% 90%, 32% 55%, 3% 34%, 39% 34%);
}

.star::before {
  content: "";
  position: absolute;
  inset: 0;
  width: calc(var(--fill) * 100%);
  background: var(--accent);
}

.rating-score {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.purchase-count {
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.buy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin-top: 2px;
  padding: 0 8px;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--cta) 0%, var(--cta-dark) 100%);
  color: white;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 10px 20px rgba(77, 143, 216, 0.28);
  transition: filter 160ms var(--ease), transform 160ms var(--ease), box-shadow 160ms var(--ease);
}

.product-card:hover .buy-button {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(77, 143, 216, 0.34);
}

.buy-button:active {
  filter: brightness(0.96);
  transform: scale(0.985);
}

.empty-state {
  margin-top: 16px;
  padding: 32px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.empty-state p {
  margin: 0;
}

.scroll-top {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: white;
  box-shadow: 0 16px 30px rgba(54, 104, 161, 0.28);
  cursor: pointer;
  transition: transform 180ms var(--ease), box-shadow 180ms var(--ease), opacity 180ms var(--ease);
}

.scroll-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 36px rgba(54, 104, 161, 0.34);
}

.scroll-top:active {
  transform: scale(0.96);
}

.scroll-top span {
  width: 15px;
  height: 15px;
  border-top: 3px solid currentColor;
  border-left: 3px solid currentColor;
  transform: translateY(4px) rotate(45deg);
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 23, 39, 0.74);
  backdrop-filter: blur(12px);
}

.lightbox-panel {
  position: relative;
  display: grid;
  gap: 12px;
  width: fit-content;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  margin: 0;
}

.lightbox-image {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 48px);
  max-height: min(78vh, 760px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.lightbox-title {
  min-width: 0;
  color: white;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 999px;
  background: rgba(23, 49, 79, 0.72);
  color: white;
  cursor: pointer;
}

.lightbox-close span,
.lightbox-close span::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.lightbox-close span {
  transform: rotate(45deg);
}

.lightbox-close span::after {
  content: "";
  transform: rotate(90deg);
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 180ms;
  animation-timing-function: var(--ease);
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 920px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .page-shell {
    width: min(calc(100vw - 20px), 520px);
    padding-top: 16px;
  }

  .toolbar {
    margin-inline: -2px;
    padding: 10px;
  }

  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .product-content {
    padding: 10px;
  }

  .product-name {
    min-height: 66px;
    font-size: 0.95rem;
    -webkit-line-clamp: 3;
  }

  .buy-button {
    font-size: 0.92rem;
  }

  .product-meta {
    display: grid;
    gap: 5px;
  }

  .purchase-count {
    text-align: left;
  }

  .image-lightbox {
    padding: 12px;
  }

  .lightbox-panel {
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .lightbox-image {
    max-width: calc(100vw - 24px);
    max-height: 78vh;
  }
}

@media (max-width: 360px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
}
