/* All sizes, colours and timings come from src/config.js as CSS variables. */

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

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--type-font-family);
  color: var(--c-text);
  background: var(--c-page-bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; }

.app {
  display: grid;
  grid-template-columns: var(--layout-sidebar-width) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--c-sidebar-bg);
  border-right: 1px solid var(--c-separator);
  padding: var(--layout-sidebar-padding);
  overflow-y: auto;
  z-index: 3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--type-brand-size);
  padding: 4px 4px 0;
  margin-bottom: var(--sidebar-brand-gap);
  white-space: nowrap;
}
.brand strong { font-weight: 600; }
.brand-icon { width: 15px; height: 15px; flex: none; }

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--sidebar-search-height);
  padding: 0 8px;
  margin-bottom: var(--sidebar-group-gap);
  background: var(--c-search-bg);
  border: 1px solid var(--c-search-border);
  border-radius: var(--sidebar-search-radius);
}
.search:focus-within { border-color: var(--c-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-accent) 25%, transparent); }
.search-icon { width: 12px; height: 12px; flex: none; color: var(--c-text-secondary); }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--c-text);
  font: inherit;
  font-size: var(--type-search-size);
}
.search input::-webkit-search-cancel-button { display: none; }

.nav { display: flex; flex-direction: column; gap: var(--sidebar-item-gap); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  height: var(--sidebar-item-height);
  padding: 0 8px;
  border-radius: var(--sidebar-item-radius);
  font-size: var(--type-nav-size);
}
.nav-item:hover { background: color-mix(in srgb, var(--c-nav-active-bg) 50%, transparent); }
.nav-item.active { background: var(--c-nav-active-bg); }
.nav-icon { width: var(--sidebar-icon-size); height: var(--sidebar-icon-size); flex: none; color: var(--c-accent); }

.nav-label {
  font-size: var(--type-nav-label-size);
  font-weight: 600;
  color: var(--c-text-secondary);
  margin: var(--sidebar-group-gap) 0 4px;
  padding: 0 4px;
}

/* ---------- Main column ---------- */

.main {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  container-type: inline-size; /* lets full-bleed sections size to the column with cqw */
}

.content {
  position: relative;
  z-index: 1;
  max-width: calc(var(--layout-content-max-width) + 2 * var(--layout-content-padding-x));
  margin: 0 auto;
  padding: var(--layout-content-padding-top) var(--layout-content-padding-x) var(--layout-content-padding-bottom);
}

.page-title {
  font-size: var(--type-page-title-size);
  font-weight: var(--type-page-title-weight);
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}
.page-blurb { margin: -8px 0 20px; color: var(--c-text-secondary); font-size: var(--type-tile-title-size); }
.empty { color: var(--c-text-secondary); }
.requirements { margin: 0 0 8px; padding-left: 20px; font-size: var(--type-detail-body-size); line-height: 1.7; }
.empty a { color: var(--c-accent); }

.section { margin-top: var(--layout-section-gap); }
.page-title + .section, .page-blurb + .section { margin-top: 0; }

.section-title {
  font-size: var(--type-section-title-size);
  font-weight: 700;
  margin: 0 0 var(--list-header-gap);
}
.section-title a { display: inline-flex; align-items: center; gap: 3px; }
.section-chevron { width: 12px; height: 12px; color: var(--c-text-tertiary); }

/* Blurred colour wash behind the top of Discover */
.backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hero-backdrop-height);
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 25%, transparent);
  mask-image: linear-gradient(to bottom, #000 25%, transparent);
}
.backdrop-layer {
  position: absolute;
  inset: calc(-2 * var(--hero-backdrop-blur));
  filter: blur(var(--hero-backdrop-blur));
  opacity: 0;
  transition: opacity var(--hero-backdrop-fade-ms) ease;
}
.backdrop-layer.on { opacity: var(--hero-backdrop-opacity); }

/* ---------- Generated artwork ---------- */

.art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: size;
}
.art::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 20;
  background: linear-gradient(125deg, rgb(255 255 255 / var(--sheen)) 0%, transparent 38%, transparent 70%, rgb(255 255 255 / calc(var(--sheen) / 2)) 100%);
  pointer-events: none;
}
.art--photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
}
.art--photo .photo-compact { display: none; }
body.compact .art--photo .photo-wide { display: none; }
body.compact .art--photo .photo-compact { display: block; }

.art-orb {
  position: absolute;
  aspect-ratio: 1;
  border-radius: 50%;
}
.art-icon {
  position: absolute;
  aspect-ratio: 1;
  filter: drop-shadow(0 2cqh 4cqh rgb(0 0 0 / var(--shadow)));
}

.app-icon {
  width: 100%;
  aspect-ratio: 1;
  border-radius: calc(var(--icon-corner-ratio) * 100%);
  background: linear-gradient(170deg, var(--icon-a), var(--icon-b));
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: inset 0 0 0 0.5px rgb(0 0 0 / 0.12), inset 0 1px 0 rgb(255 255 255 / 0.35);
  overflow: hidden;
}
.app-icon svg {
  width: calc(var(--icon-glyph-scale) * 100%);
  height: calc(var(--icon-glyph-scale) * 100%);
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.15));
}
.app-icon--image { background: none; box-shadow: none; }
.app-icon--image img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Level 1: hero slider ---------- */

.hero {
  position: relative;
  aspect-ratio: var(--hero-aspect-ratio);
  border-radius: var(--hero-radius);
  overflow: hidden;
  box-shadow: 0 6px 24px var(--c-shadow);
  user-select: none;
  touch-action: pan-y;
  isolation: isolate;
}
.hero-track {
  display: flex;
  height: 100%;
  transition: transform var(--hero-transition-ms) cubic-bezier(0.4, 0, 0.2, 1);
}
.hero-slide {
  position: relative;
  flex: 0 0 100%;
  height: 100%;
  color: var(--c-hero-text);
  -webkit-user-drag: none;
}
.hero-slide::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 21;
  background: linear-gradient(to top, rgb(0 0 0 / var(--hero-scrim-opacity)) 0%, transparent 45%);
}
.hero-text {
  position: absolute;
  z-index: 22;
  left: var(--hero-text-padding-x);
  right: var(--hero-text-padding-x);
  bottom: var(--hero-text-padding-bottom);
}
.hero-eyebrow {
  font-size: var(--type-hero-eyebrow-size);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.8;
}
.hero-title {
  font-size: var(--type-hero-title-size);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 6px 0 4px;
}
.hero-subtitle { font-size: var(--type-hero-subtitle-size); opacity: 0.85; }

.hero-dots {
  position: absolute;
  z-index: 23;
  bottom: var(--hero-dots-bottom);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: var(--hero-dot-gap);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.22);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.hero-dot {
  width: var(--hero-dot-size);
  height: var(--hero-dot-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #fff;
  opacity: var(--hero-dot-inactive-opacity);
  cursor: pointer;
  transition: opacity 200ms;
}
.hero-dot.active { opacity: 1; }

/* ---------- Level 2: big tiles ---------- */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--tiles-min-column-width), 100%), 1fr));
  gap: var(--tiles-row-gap) var(--tiles-column-gap);
}
.tile { display: block; min-width: 0; }
.tile-media {
  position: relative;
  aspect-ratio: var(--tiles-image-aspect);
  border-radius: var(--tiles-radius);
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 1px 3px var(--c-shadow);
}
.tile-media .art { transition: transform var(--tiles-hover-ms) ease; }
.tile:hover .tile-media .art { transform: scale(var(--tiles-hover-scale)); }
.tile-eyebrow {
  margin-top: var(--tiles-text-gap);
  font-size: var(--type-tile-eyebrow-size);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--c-text-secondary);
}
.tile-title { font-size: var(--type-tile-title-size); margin-top: 3px; }
.tile-desc { font-size: var(--type-tile-desc-size); color: var(--c-text-secondary); margin-top: 3px; line-height: 1.35; }

/* ---------- Level 3: small app rows ---------- */

.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--list-min-column-width), 100%), 1fr));
  column-gap: var(--list-column-gap);
}
.list-row, .category-card {
  display: flex;
  align-items: center;
  gap: var(--list-icon-gap);
  min-height: var(--list-row-height);
  min-width: 0;
}
.list-icon { width: var(--list-icon-size); flex: none; }
.list-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.list-name {
  font-size: var(--type-list-name-size);
  font-weight: 500;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.list-sub {
  font-size: var(--type-list-subtitle-size);
  color: var(--c-text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: var(--list-button-height);
  padding: 0 var(--list-button-padding-x);
  border-radius: 999px;
  background: var(--c-button-bg);
  color: var(--c-accent);
  font-size: var(--type-button-size);
  font-weight: 700;
  transition: background 150ms;
}
.pill:hover { background: var(--c-button-bg-hover); }

.category-icon {
  width: var(--list-icon-size);
  height: var(--list-icon-size);
  padding: calc(var(--list-icon-size) / 4.5);
  flex: none;
  color: var(--c-accent);
  background: var(--c-card-bg);
  border-radius: calc(var(--icon-corner-ratio) * var(--list-icon-size));
}

/* ---------- App detail ---------- */

/* Blurred header: full-bleed across the main column (escapes the centred content
   width via container units), flush with the top, rounded at the bottom */
.detail-hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  margin: calc(-1 * var(--layout-content-padding-top)) calc((100% - 100cqw) / 2) 0;
  border-radius: 0 0 var(--detail-hero-radius) var(--detail-hero-radius);
  color: #fff;
}
.detail-hero-bg {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-size: cover;
  background-position: center;
  filter: blur(var(--detail-hero-blur)) saturate(1.2);
  transform: scale(var(--detail-hero-bg-scale));
}
.detail-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgb(0 0 0 / var(--detail-hero-dim-opacity));
}
.detail-hero-inner {
  display: flex;
  align-items: center;
  gap: var(--detail-header-gap);
  /* Same width as .content so the icon lines up with the stats and body below */
  max-width: calc(var(--layout-content-max-width) + 2 * var(--layout-content-padding-x));
  margin: 0 auto;
  padding: var(--detail-hero-padding-y) calc(var(--layout-content-padding-x) + var(--detail-hero-padding-x));
}
.detail-icon { width: var(--detail-icon-size); flex: none; filter: drop-shadow(0 8px 18px rgb(0 0 0 / 0.3)); }
.detail-info { min-width: 0; }
.detail-title { font-size: var(--type-detail-title-size); font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.detail-subtitle { font-size: var(--type-detail-subtitle-size); font-weight: 600; margin-top: 4px; opacity: 0.92; }
.detail-platform { font-size: var(--type-detail-platform-size); margin-top: 12px; opacity: 0.8; }
.detail-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.button-primary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: var(--detail-button-height);
  padding: 0 var(--detail-button-padding-x);
  border-radius: 999px;
  background: var(--c-accent);
  color: #fff;
  font-weight: 600;
  font-size: var(--type-list-name-size);
  white-space: nowrap;
}
.button-primary:hover { filter: brightness(1.08); }
.button-primary.is-disabled { background: var(--c-button-bg); color: var(--c-text-secondary); filter: none; cursor: default; }
.detail-hero .button-primary.is-disabled { background: rgb(255 255 255 / 0.2); color: rgb(255 255 255 / 0.85); }
.button-arrow { width: 12px; height: 12px; }
.share-button {
  display: grid;
  place-items: center;
  width: var(--detail-share-size);
  height: var(--detail-share-size);
  padding: 7px;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.22);
  color: #fff;
  cursor: pointer;
}
.share-button:hover { background: rgb(255 255 255 / 0.32); }
.share-button.is-done { background: rgb(255 255 255 / 0.4); }
.share-button svg { width: 100%; height: 100%; }

/* Stats row */
.detail-stats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--detail-stats-gap);
  padding: var(--detail-stats-padding-y) var(--detail-hero-padding-x);
  border-bottom: 1px solid var(--c-separator);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  min-width: 0;
}
.stat-label {
  font-size: var(--type-detail-stat-label-size);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--c-text-secondary);
}
.stat-value {
  display: grid;
  place-items: center;
  height: calc(var(--type-detail-stat-value-size) * 1.3);
  font-size: var(--type-detail-stat-value-size);
  font-weight: 700;
  color: var(--c-text-secondary);
}
.stat-glyph { width: calc(var(--type-detail-stat-value-size) * 1.1); height: calc(var(--type-detail-stat-value-size) * 1.1); }
.stat-sub { font-size: var(--type-detail-stat-sub-size); color: var(--c-text-secondary); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.stat:hover .stat-sub { color: var(--c-accent); }

/* Screenshots, platform and description */
.detail-body { padding: 0 var(--detail-hero-padding-x); }
.detail-shots {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(var(--detail-screenshot-min-width), 1fr);
  gap: var(--detail-screenshot-gap);
  margin-top: var(--detail-screenshot-gap);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.detail-shot {
  aspect-ratio: var(--detail-screenshot-aspect);
  padding: var(--detail-screenshot-padding);
  overflow: hidden;
  background: var(--c-card-bg);
  border: 1px solid var(--c-separator);
  border-radius: var(--detail-screenshot-radius);
  scroll-snap-align: start;
}
.detail-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-platform-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--c-separator);
  font-size: var(--type-list-name-size);
  color: var(--c-text-secondary);
}
.platform-icon { width: 18px; height: 18px; }
.detail-desc-wrap { position: relative; max-width: 80ch; margin-top: 18px; }
.detail-desc {
  margin: 0;
  font-size: var(--type-detail-body-size);
  line-height: 1.55;
  white-space: pre-line;
}
.detail-desc.is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: var(--detail-description-lines);
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.detail-more {
  display: block;
  margin-left: auto;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--c-accent);
  font-size: var(--type-detail-body-size);
  cursor: pointer;
}
.detail-more[hidden] { display: none; }

/* ---------- Compact mode (narrow windows) ---------- */

.topbar, .scrim { display: none; }

body.compact .app { grid-template-columns: 1fr; height: calc(100dvh - var(--layout-topbar-height)); }
body.compact .topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--layout-topbar-height);
  padding: 0 12px;
  background: var(--c-sidebar-bg);
  border-bottom: 1px solid var(--c-separator);
  font-size: var(--type-brand-size);
}
body.compact .topbar-brand { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
body.compact .topbar-brand strong { font-weight: 600; }
.topbar-menu { width: 32px; height: 32px; padding: 6px; border: 0; background: none; color: var(--c-accent); cursor: pointer; }
.topbar-menu svg { width: 100%; height: 100%; }

body.compact .sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--layout-sidebar-width);
  transform: translateX(-100%);
  transition: transform 250ms ease;
}
body.compact.drawer-open .sidebar { transform: none; box-shadow: 0 0 40px var(--c-shadow); }
body.compact.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 2; background: rgb(0 0 0 / 0.3); }
body.compact .content { padding-left: 16px; padding-right: 16px; }
body.compact .hero { aspect-ratio: var(--hero-compact-aspect-ratio); }
body.compact .detail-hero-inner { flex-direction: column; align-items: flex-start; padding: var(--detail-compact-padding) 16px; }
body.compact .detail-stats {
  grid-auto-flow: row;
  grid-template-columns: repeat(auto-fit, minmax(var(--detail-compact-stat-min-width), 1fr));
  row-gap: var(--detail-compact-padding);
  padding: var(--detail-compact-padding) 0;
}
body.compact .detail-body { padding: 0; }
