:root {
  --bg: #f0f0f0;
  --card-bg: #fff;
  --text: #111;
  --text-muted: #888;
  --border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.15);
  --radius: 16px;
  --gap: 64px;
  --col-w: calc((100vw - 160px) / 3.2);
  --row-h: calc((100vh - 100px) / 2.3);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 400ms;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  /* The canvas handles its own panning; stop the browser scrolling/zooming the page */
  position: fixed;
  inset: 0;
  touch-action: none;
}

.modal-overlay,
.filter-overlay {
  touch-action: pan-y;
}

body.dragging {
  cursor: grabbing;
}

/* Floating nav */
.nav-left {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-pill {
  background: #111;
  color: #fff;
  padding: 12px 24px;
  border-radius: 28px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
  text-decoration: none;
}

.nav-pill:hover {
  background: #222;
}

.nav-pill .divider {
  width: 1px;
  height: 16px;
  background: rgba(255, 255, 255, 0.2);
}

.nav-pill svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Bottom search */
.nav-bottom {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  gap: 8px;
}

.nav-bottom-btn {
  height: 48px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  color: #555;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--duration-fast) ease;
}

.nav-bottom-btn:hover {
  background: rgba(255, 255, 255, 0.95);
}

.nav-bottom-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Canvas */
.canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(var(--cols, 7), var(--col-w));
  grid-auto-rows: var(--row-h);
  gap: var(--gap);
  transform: translate(-50%, -50%);
  will-change: transform;
  pointer-events: auto;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition:
    transform var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out);
  text-decoration: none;
  color: inherit;
}

@media (hover: hover) and (pointer: fine) {
  .card:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
  }

  .card:hover .card-name {
    opacity: 1;
    transform: translateY(0);
  }

  .card:hover .card-video {
    opacity: 1;
  }
}

/* Touch: no hover, so reveal hover videos while the card is on screen */
@media (hover: none) {
  .card.in-view video.card-video {
    opacity: 1;
  }
}

.card:active {
  transform: scale(0.98);
}

.card-media {
  width: 100%;
  height: 100%;
  position: relative;
}

.card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-out);
  pointer-events: none;
}

/* Glass name badge (hover only) */
.card-name {
  position: absolute;
  bottom: 14px;
  left: 14px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #333;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 180ms var(--ease-out),
    transform 180ms var(--ease-out);
  pointer-events: none;
}

/* Video badge (top-right) */
.video-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.video-badge svg {
  width: 12px;
  height: 12px;
  fill: #fff;
}

/* Center card */
.center-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px;
  text-align: center;
  background: var(--card-bg);
  cursor: default;
}

@media (hover: hover) and (pointer: fine) {
  .center-card:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
  }
}

.center-icon {
  color: #999;
  font-size: 40px;
}

.center-title {
  font-size: 28px;
  font-weight: 500;
  color: #111;
  line-height: 1.3;
  max-width: 320px;
}

.center-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-primary {
  display: inline-flex;
  height: 44px;
  align-items: center;
  gap: 8px;
  background: #000;
  color: #fff;
  padding: 0 22px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--duration-fast) ease,
    transform 100ms ease;
  font-family: inherit;
}

.btn-primary:hover {
  background: rgba(0, 0, 0, 0.88);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  display: inline-flex;
  height: 44px;
  align-items: center;
  gap: 8px;
  background: #f0f0f0;
  color: #666;
  padding: 0 22px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--duration-fast) ease,
    transform 100ms ease;
  font-family: inherit;
}

.btn-secondary:hover {
  background: #e5e5e5;
}

.btn-secondary:active {
  transform: scale(0.98);
}

/* Phones */
@media (max-width: 640px) {
  :root {
    --gap: 16px;
    --col-w: 74vw;
    --row-h: calc(74vw * 1.15);
  }

  .nav-left {
    top: 16px;
    left: 16px;
  }

  .nav-bottom {
    bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .center-card {
    gap: 14px;
    padding: 24px 20px;
  }

  .center-icon {
    font-size: 28px;
  }

  .center-title {
    font-size: 22px;
  }

  .center-buttons {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .center-buttons .btn-primary,
  .center-buttons .btn-secondary {
    justify-content: center;
  }

  .card-name {
    opacity: 1;
    transform: none;
    bottom: 10px;
    left: 10px;
    font-size: 13px;
    padding: 6px 14px;
  }

  .filter-overlay {
    padding: 64px 16px 0;
  }

  .filter-modal {
    padding: 24px 20px;
  }
}

/* Loading state */
.loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: 14px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .card {
    transition: opacity var(--duration-normal) ease;
  }
  .card:hover {
    transform: none;
  }
  video.card-video {
    display: none;
  }
}

/* Card dim/highlight states for filter */
.card.dim {
  opacity: 0.18;
  filter: saturate(0.4);
  transition: opacity var(--duration-normal) var(--ease-out), filter var(--duration-normal) var(--ease-out);
}
.card.highlight {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2), var(--shadow-md);
}

/* Filter modal */
.filter-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.filter-overlay.active {
  display: flex;
}
.filter-modal {
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px;
  width: 100%;
  max-width: 560px;
  padding: 32px;
  position: relative;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.6);
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  transform: scale(0.95);
  opacity: 0;
  transition: transform var(--duration-normal) var(--ease-out), opacity var(--duration-normal) var(--ease-out);
}
.filter-overlay.active .filter-modal {
  transform: scale(1);
  opacity: 1;
}
.filter-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  background: rgba(0, 0, 0, 0.06);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  color: #666;
  transition: background var(--duration-fast) ease;
}
.filter-close:hover {
  background: rgba(0, 0, 0, 0.12);
}
.filter-heading {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #111;
}
.filter-search {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  font-size: 15px;
  background: #fff;
  outline: none;
  transition: border-color var(--duration-fast) ease;
  font-family: inherit;
  margin-bottom: 24px;
}
.filter-search:focus {
  border-color: #5de6c8;
}
.filter-search::placeholder {
  color: #bbb;
}
.filter-section {
  margin-bottom: 20px;
}
.filter-section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #999;
  margin-bottom: 10px;
}
.filter-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-pill {
  background: rgba(0, 0, 0, 0.05);
  color: #555;
  border: none;
  padding: 7px 14px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) ease, color var(--duration-fast) ease;
  font-family: inherit;
}
.filter-pill:hover {
  background: rgba(0, 0, 0, 0.09);
}
.filter-pill.active {
  background: #111;
  color: #fff;
}
.filter-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.filter-clear {
  background: transparent;
  color: #888;
  border: none;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--duration-fast) ease;
}
.filter-clear:hover {
  background: rgba(0, 0, 0, 0.05);
}
.filter-done {
  background: #111;
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--duration-fast) ease;
}
.filter-done:hover {
  background: #222;
}
